//
//  DataHandle.m
//  DongChiDaChiProject1
//
//  Created by lanou3g on 15/10/28.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "DataHandle.h"

@interface DataHandle ()

// 建立一个数组存储美食界面的model
@property (nonatomic, strong) NSMutableArray *meishiDataArray;

// 定义一个数组进行存储上一个界面的数据
@property (nonatomic, strong) NSMutableArray *saveLastDataArray;

// 建立一个数组存储靓汤界面的数据
@property (nonatomic, strong) NSMutableArray *qiangtangDataArray;

// 定义一个数组进行存储上一个界面的数据
@property (nonatomic, strong) NSMutableArray *saveQiangtangLastDataArray;

// 建立一个数组存储特色小吃界面的数据
@property (nonatomic, strong) NSMutableArray *teSeXiaoChiDataArray;

// 定义一个数组进行存储特色小吃上一个界面的数据
@property (nonatomic, strong) NSMutableArray *saveTeSeXiaoChiLastDataArray;

// 建立一个数组存储凉菜界面的数据
@property (nonatomic, strong) NSMutableArray *liangCaiDataArray;

// 定义一个数组进行存储凉菜上一个界面的数据
@property (nonatomic, strong) NSMutableArray *saveLiangCaiLastDataArray;

// 建立一个数组存储时尚饮品界面的数据
@property (nonatomic, strong) NSMutableArray *shiShangYinPinDataArray;

// 定义一个数组进行存储时尚饮品上一个界面的数据
@property (nonatomic, strong) NSMutableArray *saveShiShangYinPinLastDataArray;

// 建立一个数组存储甜品界面的数据
@property (nonatomic, strong) NSMutableArray *tianPinDataArray;

// 定义一个数组进行存储甜品上一个界面的数据
@property (nonatomic, strong) NSMutableArray *saveTianPinLastDataArray;

// 建立一个数组存储食疗药膳界面的数据
@property (nonatomic, strong) NSMutableArray *shiLiaoYaoShanDataArray;

// 定义一个数组进行存储食疗药膳上一个界面的数据
@property (nonatomic, strong) NSMutableArray *saveShiLiaoYaoShanLastDataArray;

// 建立一个数组存储美粥界面的数据
@property (nonatomic, strong) NSMutableArray *meiZhouDataArray;

// 定义一个数组进行存储美粥上一个界面的数据
@property (nonatomic, strong) NSMutableArray *saveMeiZhouLastDataArray;

@end

@implementation DataHandle

+ (DataHandle *)shareHandle
{
    static DataHandle *dataHandle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dataHandle = [[DataHandle alloc] init];
        dataHandle.saveLastDataArray = [NSMutableArray array];
        dataHandle.saveQiangtangLastDataArray = [NSMutableArray array];
        dataHandle.saveTeSeXiaoChiLastDataArray = [NSMutableArray array];
        dataHandle.saveLiangCaiLastDataArray = [NSMutableArray array];
        dataHandle.saveShiShangYinPinLastDataArray = [NSMutableArray array];
        dataHandle.saveTianPinLastDataArray = [NSMutableArray array];
        dataHandle.saveShiLiaoYaoShanLastDataArray = [NSMutableArray array];
        dataHandle.saveMeiZhouLastDataArray = [NSMutableArray array];
    });
    return dataHandle;
}

#pragma mark - 删除保存数组的内容
- (void)deleteQianTangSaveArray
{
    [self.saveQiangtangLastDataArray removeAllObjects];
}

- (void)deleteTeSeXiaoChiSaveArray
{
    [self.saveTeSeXiaoChiLastDataArray removeAllObjects];
}

- (void)deleteLiangCaiSaveArray
{
    [self.saveLiangCaiLastDataArray removeAllObjects];
}

- (void)deleteShiShangYinPinSaveArray
{
    [self.saveShiLiaoYaoShanLastDataArray removeAllObjects];
}

- (void)deleteTianPinSaveArray
{
    [self.saveTianPinLastDataArray removeAllObjects];
}

- (void)deleteShiLiaoYaoShanSaveArray
{
    [self.saveShiLiaoYaoShanLastDataArray removeAllObjects];
}

- (void)deleteMeiZhouSaveArray
{
    [self.saveMeiZhouLastDataArray removeAllObjects];
}

// 删除首页的保存数组
- (void)deleteShouYeSaveArray
{
    [self.saveLastDataArray removeAllObjects];
}


#pragma mark - 美食数据
// 请求热门美食数据并且用block回调
- (void)requestHotMeiShiDataWithPage:(NSInteger)PageCount AndReturn:(void(^)(NSMutableArray *array))block
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.meishiDataArray = [NSMutableArray array];
        switch (PageCount) {
            case 1:
            {
                // 请求数据
                NSURL *url = [NSURL URLWithString:kMeiShiURL1];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    
                    // NSLog(@"data = %@", data);
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultArray) {
                        HotMeiShiModel *model = [[HotMeiShiModel alloc] init];
                        
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.meishiDataArray addObject:model];
                    }
                    //NSLog(@"self.meishiDataArray = %@ ", self.meishiDataArray);
                    [self.saveLastDataArray addObjectsFromArray:self.meishiDataArray];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.meishiDataArray);
                    });
                    
                    
                    
                    
                }];
                [dataTask resume];
                break;
            }
                
                
             case 2:
            {
                // 请求数据
                NSURL *url = [NSURL URLWithString:kMeiShiURL2];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    
                    // NSLog(@"data = %@", data);
                    // 首先获得上一个界面的数据
                    [self.meishiDataArray addObjectsFromArray:self.saveLastDataArray];
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray*resultArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultArray) {
                        HotMeiShiModel *model = [[HotMeiShiModel alloc] init];
                        
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.meishiDataArray addObject:model];
                    }
                   // NSLog(@"self.meishiDataArray = %@, count = %ld ", self.meishiDataArray, self.meishiDataArray.count);
                    // 先要清除之前的数据
                    [self.saveLastDataArray removeAllObjects];
                    [self.saveLastDataArray addObjectsFromArray:self.meishiDataArray];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.meishiDataArray);
                    });
                    
                    
                    
                    
                }];
                [dataTask resume];
                break;
            }
                case 3:
            {
                // 请求数据
                NSURL *url = [NSURL URLWithString:kMeiShiURL3];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    
                    // NSLog(@"data = %@", data);
                    // 首先获得上一个界面的数据
                    [self.meishiDataArray addObjectsFromArray:self.saveLastDataArray];
                    NSLog(@"更新之前%ld", (unsigned long)self.saveLastDataArray.count);
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultArray) {
                        HotMeiShiModel *model = [[HotMeiShiModel alloc] init];
                        
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.meishiDataArray addObject:model];
                    }
                  //  NSLog(@"self.meishiDataArray = %@, count = %ld ", self.meishiDataArray, self.meishiDataArray.count);
                    [self.saveLastDataArray removeAllObjects];
                    [self.saveLastDataArray addObjectsFromArray:self.meishiDataArray];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.meishiDataArray);
                    });
                    
                    
                    
                    
                }];
                [dataTask resume];
                break;
            }
                
            default:
                break;
        }
       
 
        
    });
    
    
}

// 根据indexpath返回model
- (HotMeiShiModel *)returnHotMeiShiModelByIndex:(NSIndexPath *)indexPath
{
    if (!(self.meishiDataArray.count > indexPath.row)) {
        return nil;
    }
    return self.meishiDataArray[indexPath.row];
}
// 返回HotMeiShiModel的个数
- (NSInteger)returnCountOfHotMeiShiModel
{
    NSLog(@"self.meishiDataArray.count = %ld", (unsigned long)self.meishiDataArray.count);
    return self.meishiDataArray.count;
}

#pragma mark - 靓汤数据
// 请求热门美食数据并且用block回调
- (void)requestQiangTangDataWithPage:(NSInteger)PageCount AndReturn:(void(^)(NSMutableArray *array))block
{
   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
       self.qiangtangDataArray = [NSMutableArray array];
       switch (PageCount) {
           case 1:
           {
               NSURL *url = [NSURL URLWithString:kQianTang1];
               NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
               [request setHTTPMethod:@"GET"];
               NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
               NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
               NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                   if (!data) {
                       return;
                   }
                  // NSLog(@"data = %@", data);
                   
                   NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                   NSArray *resultsArray = [dic valueForKey:@"results"];
                   for (NSDictionary *tempDic in resultsArray) {
                       QiangTangModel *model = [[QiangTangModel alloc] init];
                       [model setValuesForKeysWithDictionary:tempDic];
                       [self.qiangtangDataArray addObject:model];
                   }
                   
                   // 保存
                   [self.saveQiangtangLastDataArray addObjectsFromArray:self.qiangtangDataArray];
                   
                 
                   dispatch_async(dispatch_get_main_queue(), ^{
                       block(self.qiangtangDataArray);
                   });
                   
               }];
               [dataTask resume];
               break;
           }
               case 2:
           {
               NSURL *url = [NSURL URLWithString:kQianTang2];
               NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
               [request setHTTPMethod:@"GET"];
               NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
               NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
               NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                   if (!data) {
                       return;
                   }
                   // NSLog(@"data = %@", data);
                   // 保存上一个界面的东西
                   [self.qiangtangDataArray addObjectsFromArray:self.saveQiangtangLastDataArray];
                   
                   NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                   NSArray *resultsArray = [dic valueForKey:@"results"];
                   for (NSDictionary *tempDic in resultsArray) {
                       QiangTangModel *model = [[QiangTangModel alloc] init];
                       [model setValuesForKeysWithDictionary:tempDic];
                       [self.qiangtangDataArray addObject:model];
                   }
                   // 先删除
                   [self.saveQiangtangLastDataArray removeAllObjects];
                   [self.saveQiangtangLastDataArray addObjectsFromArray:self.qiangtangDataArray];
                   // NSLog(@"self.qiangtangDataArray = %@", self.qiangtangDataArray);
                   
        
                   dispatch_async(dispatch_get_main_queue(), ^{
                       block(self.qiangtangDataArray);
                   });
                   
               }];
               [dataTask resume];
               break;
           }
               case 3:
           {
               NSURL *url = [NSURL URLWithString:kQianTang3];
               NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
               [request setHTTPMethod:@"GET"];
               NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
               NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
               NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                   if (!data) {
                       return;
                   }
                   // NSLog(@"data = %@", data);
                   // 保存上一个界面的东西
                   [self.qiangtangDataArray addObjectsFromArray:self.saveQiangtangLastDataArray];
                   
                   NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                   NSArray *resultsArray = [dic valueForKey:@"results"];
                   for (NSDictionary *tempDic in resultsArray) {
                       QiangTangModel *model = [[QiangTangModel alloc] init];
                       [model setValuesForKeysWithDictionary:tempDic];
                       [self.qiangtangDataArray addObject:model];
                   }
                   // 先删除
                   [self.saveQiangtangLastDataArray removeAllObjects];
                   [self.saveQiangtangLastDataArray addObjectsFromArray:self.qiangtangDataArray];
//                    NSLog(@"self.qiangtangDataArray.count = %ld", self.qiangtangDataArray.count);
                
                   dispatch_async(dispatch_get_main_queue(), ^{
                       block(self.qiangtangDataArray);
                   });
                   
               }];
               [dataTask resume];
               break;

           }
           default:
               break;
       }
       
       
       
       
   });
    
    
}
// 根据indexpath返回model
- (QiangTangModel*)returnQiangTangModelByIndex:(NSIndexPath *)indexPath
{
    if (!(self.qiangtangDataArray.count > indexPath.row)) {
        return nil;
    }
   return self.qiangtangDataArray[indexPath.row];
}
// 返回HotMeiShiModel的个数
- (NSInteger)returnCountOfQiangTangModel
{
    NSLog(@"self.qiangtangDataArray.count = %ld", (unsigned long)self.qiangtangDataArray.count);
    return self.qiangtangDataArray.count;
}

#pragma mark - 特色小吃
// 请求热门美食数据并且用block回调
- (void)requestTeSeXiaoChiDataWithPage:(NSInteger)PageCount AndReturn:(void(^)(NSMutableArray *array))block
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.teSeXiaoChiDataArray = [NSMutableArray array];
        switch (PageCount) {
            case 1:
            {
                NSURL *url = [NSURL URLWithString:kTeSeXiaoChi1];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        TeSeXiaoChiModel *model = [[TeSeXiaoChiModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.teSeXiaoChiDataArray addObject:model];
                    }
                    
                    // 保存
                    [self.saveTeSeXiaoChiLastDataArray addObjectsFromArray:self.teSeXiaoChiDataArray];
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.teSeXiaoChiDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 2:
            {
                NSURL *url = [NSURL URLWithString:kTeSeXiaoChi2];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.teSeXiaoChiDataArray addObjectsFromArray:self.saveTeSeXiaoChiLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        TeSeXiaoChiModel *model = [[TeSeXiaoChiModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.teSeXiaoChiDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveTeSeXiaoChiLastDataArray removeAllObjects];
                    [self.saveTeSeXiaoChiLastDataArray addObjectsFromArray:self.teSeXiaoChiDataArray];
                    // NSLog(@"self.qiangtangDataArray = %@", self.qiangtangDataArray);
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.teSeXiaoChiDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 3:
            {
                NSURL *url = [NSURL URLWithString:kTeSeXiaoChi3];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.teSeXiaoChiDataArray addObjectsFromArray:self.saveTeSeXiaoChiLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        TeSeXiaoChiModel *model = [[TeSeXiaoChiModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.teSeXiaoChiDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveTeSeXiaoChiLastDataArray removeAllObjects];
                    [self.saveTeSeXiaoChiLastDataArray addObjectsFromArray:self.teSeXiaoChiDataArray];
                    //                    NSLog(@"self.qiangtangDataArray.count = %ld", self.qiangtangDataArray.count);
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.teSeXiaoChiDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
                
            }
            default:
                break;
        }
        
        
        
        
    });
    

}
// 根据indexpath返回model
- (TeSeXiaoChiModel*)returnTeSeXiaoChiModelByIndex:(NSIndexPath *)indexPath
{
    if (!(self.teSeXiaoChiDataArray.count > indexPath.row)) {
        return nil;
    }
    return self.teSeXiaoChiDataArray[indexPath.row];
}
// 返回HotMeiShiModel的个数
- (NSInteger)returnCountOfTeSeXiaoChiModel
{
    NSLog(@"self.teSeXiaoChiDataArray.count = %ld", (unsigned long)self.teSeXiaoChiDataArray.count);
    return self.teSeXiaoChiDataArray.count;
}

#pragma mark - 凉菜
// 请求凉菜数据并且用block回调
- (void)requestTeLiangCaiDataWithPage:(NSInteger)PageCount AndReturn:(void(^)(NSMutableArray *array))block
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.liangCaiDataArray = [NSMutableArray array];
        switch (PageCount) {
            case 1:
            {
                NSURL *url = [NSURL URLWithString:kLiangCai1];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        LiangCaiModel *model = [[LiangCaiModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.liangCaiDataArray addObject:model];
                    }
                    
                    // 保存
                    [self.saveLiangCaiLastDataArray addObjectsFromArray:self.liangCaiDataArray];
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.liangCaiDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 2:
            {
                NSURL *url = [NSURL URLWithString:kLiangCai2];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.liangCaiDataArray addObjectsFromArray:self.saveLiangCaiLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        LiangCaiModel *model = [[LiangCaiModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.liangCaiDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveLiangCaiLastDataArray removeAllObjects];
                    [self.saveLiangCaiLastDataArray addObjectsFromArray:self.liangCaiDataArray];
                    // NSLog(@"self.qiangtangDataArray = %@", self.qiangtangDataArray);
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.liangCaiDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 3:
            {
                NSURL *url = [NSURL URLWithString:kLiangCai3];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.liangCaiDataArray addObjectsFromArray:self.saveLiangCaiLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        LiangCaiModel *model = [[LiangCaiModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.liangCaiDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveLiangCaiLastDataArray removeAllObjects];
                    [self.saveLiangCaiLastDataArray addObjectsFromArray:self.liangCaiDataArray];
                    //                    NSLog(@"self.qiangtangDataArray.count = %ld", self.qiangtangDataArray.count);
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.liangCaiDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
                
            }
            default:
                break;
        }
        
        
        
        
    });

}
// 根据indexpath返回凉菜model
- (LiangCaiModel *)returnLiangCaiModelByIndex:(NSIndexPath *)indexPath
{
    if (!(self.liangCaiDataArray.count > indexPath.row)) {
        return nil;
    }
    return self.liangCaiDataArray[indexPath.row];
}
// 返回凉菜的个数
- (NSInteger)returnCountOfLiangCaiModel
{
    return self.liangCaiDataArray.count;
}

#pragma mark - 时尚饮品
// 请求时尚饮品数据并且用block回调
- (void)requestTeShiShangYinPinDataWithPage:(NSInteger)PageCount AndReturn:(void(^)(NSMutableArray *array))block
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.shiShangYinPinDataArray = [NSMutableArray array];
        switch (PageCount) {
            case 1:
            {
                NSURL *url = [NSURL URLWithString:kShiShangYinPin1];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        ShiShangYinPinModel *model = [[ShiShangYinPinModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.shiShangYinPinDataArray addObject:model];
                    }
                    
                    // 保存
                    [self.saveShiShangYinPinLastDataArray addObjectsFromArray:self.shiShangYinPinDataArray];
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.shiShangYinPinDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 2:
            {
                NSURL *url = [NSURL URLWithString:kShiShangYinPin2];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.shiShangYinPinDataArray addObjectsFromArray:self.saveShiShangYinPinLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        ShiShangYinPinModel *model = [[ShiShangYinPinModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.shiShangYinPinDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveShiShangYinPinLastDataArray removeAllObjects];
                    [self.saveShiShangYinPinLastDataArray addObjectsFromArray:self.shiShangYinPinDataArray];
                    // NSLog(@"self.qiangtangDataArray = %@", self.qiangtangDataArray);
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.shiShangYinPinDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 3:
            {
                NSURL *url = [NSURL URLWithString:kShiShangYinPin3];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.shiShangYinPinDataArray addObjectsFromArray:self.saveShiShangYinPinLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        ShiShangYinPinModel *model = [[ShiShangYinPinModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.shiShangYinPinDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveShiShangYinPinLastDataArray removeAllObjects];
                    [self.saveShiShangYinPinLastDataArray addObjectsFromArray:self.shiShangYinPinDataArray];
                    //                    NSLog(@"self.qiangtangDataArray.count = %ld", self.qiangtangDataArray.count);
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.shiShangYinPinDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
                
            }
            default:
                break;
        }
        
        
        
        
    });
}
// 根据indexpath返回时尚饮品model
- (LiangCaiModel *)returnShiShangYinPinModelByIndex:(NSIndexPath *)indexPath
{
    if (!(self.shiShangYinPinDataArray.count > indexPath.row)) {
        return nil;
    }
    return self.shiShangYinPinDataArray[indexPath.row];
}
// 返回时尚饮品的个数
- (NSInteger)returnCountOfShiShangYinPinModel
{
    return self.shiShangYinPinDataArray.count;
}

#pragma mark - 甜品
// 请求甜品数据并且用block回调
- (void)requestTeTianPinDataWithPage:(NSInteger)PageCount AndReturn:(void(^)(NSMutableArray *array))block
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.tianPinDataArray = [NSMutableArray array];
        switch (PageCount) {
            case 1:
            {
                NSURL *url = [NSURL URLWithString:kTianPin1];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        TianPinModel *model = [[TianPinModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.tianPinDataArray addObject:model];
                    }
                    
                    // 保存
                    [self.saveTianPinLastDataArray addObjectsFromArray:self.tianPinDataArray];
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.tianPinDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 2:
            {
                NSURL *url = [NSURL URLWithString:kTianPin2];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.tianPinDataArray addObjectsFromArray:self.saveTianPinLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        TianPinModel *model = [[TianPinModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.tianPinDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveTianPinLastDataArray removeAllObjects];
                    [self.saveTianPinLastDataArray addObjectsFromArray:self.tianPinDataArray];
                    // NSLog(@"self.qiangtangDataArray = %@", self.qiangtangDataArray);
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.tianPinDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 3:
            {
                NSURL *url = [NSURL URLWithString:kTianPin3];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.tianPinDataArray addObjectsFromArray:self.saveTianPinLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        TianPinModel *model = [[TianPinModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.tianPinDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveTianPinLastDataArray removeAllObjects];
                    [self.saveTianPinLastDataArray addObjectsFromArray:self.tianPinDataArray];
                    //                    NSLog(@"self.qiangtangDataArray.count = %ld", self.qiangtangDataArray.count);
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.tianPinDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
                
            }
            default:
                break;
        }
        
        
        
        
    });
    

}
// 根据indexpath返回甜品model
- (TianPinModel *)returnTianPinModelByIndex:(NSIndexPath *)indexPath
{
    if (!(self.tianPinDataArray.count > indexPath.row)) {
        return nil;
    }
    return self.tianPinDataArray[indexPath.row];
}
// 返回甜品的个数
- (NSInteger)returnCountOfTianPinModel
{
    return self.tianPinDataArray.count;
}


#pragma mark - 食疗药膳
// 请求食疗药膳数据并且用block回调
- (void)requestTeShiLiaoYaoShanDataWithPage:(NSInteger)PageCount AndReturn:(void(^)(NSMutableArray *array))block
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.shiLiaoYaoShanDataArray = [NSMutableArray array];
        switch (PageCount) {
            case 1:
            {
                NSURL *url = [NSURL URLWithString:kShiLiaoYaoShan1];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        ShiLiaoYaoShanModel *model = [[ShiLiaoYaoShanModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.shiLiaoYaoShanDataArray addObject:model];
                    }
                    
                    // 保存
                    [self.saveShiLiaoYaoShanLastDataArray addObjectsFromArray:self.shiLiaoYaoShanDataArray];
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.shiLiaoYaoShanDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 2:
            {
                NSURL *url = [NSURL URLWithString:kShiLiaoYaoShan2];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.shiLiaoYaoShanDataArray addObjectsFromArray:self.saveShiLiaoYaoShanLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        ShiLiaoYaoShanModel *model = [[ShiLiaoYaoShanModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.shiLiaoYaoShanDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveShiLiaoYaoShanLastDataArray removeAllObjects];
                    [self.saveShiLiaoYaoShanLastDataArray addObjectsFromArray:self.shiLiaoYaoShanDataArray];
                    // NSLog(@"self.qiangtangDataArray = %@", self.qiangtangDataArray);
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.shiLiaoYaoShanDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
            }
            case 3:
            {
                NSURL *url = [NSURL URLWithString:kShiLiaoYaoShan3];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    // NSLog(@"data = %@", data);
                    // 保存上一个界面的东西
                    [self.shiLiaoYaoShanDataArray addObjectsFromArray:self.saveShiLiaoYaoShanLastDataArray];
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultsArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultsArray) {
                        ShiLiaoYaoShanModel *model = [[ShiLiaoYaoShanModel alloc] init];
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.shiLiaoYaoShanDataArray addObject:model];
                    }
                    // 先删除
                    [self.saveShiLiaoYaoShanLastDataArray removeAllObjects];
                    [self.saveShiLiaoYaoShanLastDataArray addObjectsFromArray:self.shiLiaoYaoShanDataArray];
                    //                    NSLog(@"self.qiangtangDataArray.count = %ld", self.qiangtangDataArray.count);
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.shiLiaoYaoShanDataArray);
                    });
                    
                }];
                [dataTask resume];
                break;
                
            }
            default:
                break;
        }
        
        
        
        
    });

}
// 根据indexpath返回食疗药膳model
- (ShiLiaoYaoShanModel *)returnShiLiaoYaoShanModelByIndex:(NSIndexPath *)indexPath
{
    if (!(self.shiLiaoYaoShanDataArray.count > indexPath.row)) {
        return nil;
    }
    return self.shiLiaoYaoShanDataArray[indexPath.row];
}
// 返回食疗药膳的个数
- (NSInteger)returnCountOfShiLiaoYaoShanModel
{
    return self.shiLiaoYaoShanDataArray.count;
}

#pragma mark - 美粥
// 请求美粥数据并且用block回调
- (void)requestTeMeiZhouDataWithPage:(NSInteger)PageCount AndReturn:(void(^)(NSMutableArray *array))block
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.meiZhouDataArray = [NSMutableArray array];
        switch (PageCount) {
            case 1:
            {
                // 请求数据
                NSURL *url = [NSURL URLWithString:kMeiZhou1];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    
                    // NSLog(@"data = %@", data);
                    
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultArray) {
                        MeiZhouModel *model = [[MeiZhouModel alloc] init];
                        
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.meiZhouDataArray addObject:model];
                    }
                    //NSLog(@"self.meishiDataArray = %@ ", self.meishiDataArray);
                    [self.saveMeiZhouLastDataArray addObjectsFromArray:self.meiZhouDataArray];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.meiZhouDataArray);
                    });
                    
                    
                    
                    
                }];
                [dataTask resume];
                break;
            }
                
                
            case 2:
            {
                // 请求数据
                NSURL *url = [NSURL URLWithString:kMeiZhou2];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    
                    // NSLog(@"data = %@", data);
                    // 首先获得上一个界面的数据
                    [self.meiZhouDataArray addObjectsFromArray:self.saveMeiZhouLastDataArray];
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultArray) {
                        MeiZhouModel *model = [[MeiZhouModel alloc] init];
                        
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.meiZhouDataArray addObject:model];
                    }
                    // NSLog(@"self.meishiDataArray = %@, count = %ld ", self.meishiDataArray, self.meishiDataArray.count);
                    // 先要清除之前的数据
                    [self.saveMeiZhouLastDataArray removeAllObjects];
                    [self.saveMeiZhouLastDataArray addObjectsFromArray:self.meiZhouDataArray];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.meiZhouDataArray);
                    });
                    
                    
                    
                    
                }];
                [dataTask resume];
                break;
            }
            case 3:
            {
                // 请求数据
                NSURL *url = [NSURL URLWithString:kMeiZhou3];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
                [request setHTTPMethod:@"GET"];
                NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                    if (!data) {
                        return;
                    }
                    
                    // NSLog(@"data = %@", data);
                    // 首先获得上一个界面的数据
                    [self.meiZhouDataArray addObjectsFromArray:self.saveMeiZhouLastDataArray];
               // NSLog(@"更新之前%ld", self.saveMeiZhouLastDataArray.count);
                    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSArray *resultArray = [dic valueForKey:@"results"];
                    for (NSDictionary *tempDic in resultArray) {
                        MeiZhouModel *model = [[MeiZhouModel alloc] init];
                        
                        [model setValuesForKeysWithDictionary:tempDic];
                        [self.meiZhouDataArray addObject:model];
                    }
                    //  NSLog(@"self.meishiDataArray = %@, count = %ld ", self.meishiDataArray, self.meishiDataArray.count);
                    [self.saveMeiZhouLastDataArray removeAllObjects];
                    [self.saveMeiZhouLastDataArray addObjectsFromArray:self.meiZhouDataArray];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        block(self.meiZhouDataArray);
                    });
                    
                    
                    
                    
                }];
                [dataTask resume];
                break;
            }
                
            default:
                break;
        }
        
        
        
    });

}
// 根据indexpath返回美粥model
- (ShiLiaoYaoShanModel *)returnMeiZhouModelByIndex:(NSIndexPath *)indexPath
{
    if (!(self.meiZhouDataArray.count > indexPath.row)) {
        return nil;
    }
    return self.meiZhouDataArray[indexPath.row];
}
// 返回美粥的个数
- (NSInteger)returnCountOfMeiZhounModel
{
    return self.meiZhouDataArray.count;
}

@end
